/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/clientService.ts" />
/// <reference path="../src/tms.ts" />

describe('getClientList',() => {
    var injector:ng.auto.IInjectorService;
    var service:IClientService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<IClientService>('clientService');
    });

    //常规无条件获取
    it('get client list normal',(done) => {
        service.getList(null, null, null, null,null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取客户单位名称包含 公司 的客户列表
    it('get client list by name \'公司\'',(done) => {
        service.getList('公司',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('公司|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取商务专员编号包含 1 的客户列表
    it('get client list by businessOfficerId \'1\'',(done) => {
        service.getList(null,'1',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|1||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

   //获取所属省份包含 江苏 的客户列表
    it('get client list by province \'江苏\'',(done) => {
        service.getList(null,null,'江苏',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||江苏|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取所属城市包含 镇江 的客户列表
    it('get client list by city \'镇江\'',(done) =>{
        service.getList(null,null,null,'镇江',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||镇江||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取地址详情 学府路 的客户列表
    it('get client list by addressDetails \'学府路\'',(done) =>{
        service.getList(null,null,null,null,'学府路',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||学府路|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 客户单位名称包含 公司, 商务专员编号包含 2, 所属省份包含 江苏, 所属城市包含 镇江, 地址详情 学府路 的客户列表
    it('get client list by name \'公司\' and by businessOfficerId \'2\' and by province \'江苏\' and by city \'镇江\' and addressDetails \'学府路\'',(done) =>{
        service.getList('公司','2','江苏','镇江','学府路',0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('公司|2|江苏|镇江|学府路|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });



    //获取客户详细
    it('get detail ',(done)=>{
        service.getDetail('2').then((res)=>{
            expect(res.data.cornet).toBe("001");
            expect(res.data.name).toBe("客户单位名称");
            expect(res.data.clientServiceOfficerId).toBe("1");
            expect(res.data.businessOfficerId).toBe("2");
            expect(res.data.province).toBe("江苏");
            expect(res.data.city).toBe("镇江");
            expect(res.data.area).toBe("京口区");
            expect(res.data.address).toBe("学府路301号");
            expect(res.data.adminUserName).toBe("默默");
            expect(res.data.adminPassword).toBe("123456");
            expect(res.data.reAdminPassword).toBe("123456");
            expect(res.data.phoneNumber).toBe("135");
            expect(res.data.products).toBe("花");
            expect(res.data.productPack).toBe("袋装");
            expect(res.data.paidWay).toBe("到付");
            expect(res.data.remarks).toBe("备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加客户
    it('add client',(done)=>{
        service.add('测试客户单位2','2','1','江苏','镇江','京口区','学府路301号','测试账户','666666','666666','18352866666','花','袋装','到付','备注').then((res)=>{
            expect(res.data.extData).toBe("测试客户单位2|2|1|江苏|镇江|京口区|学府路301号|测试账户|666666|666666|18352866666|花|袋装|到付|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑客户
    it('edit client',(done)=>{
        service.edit('3','测试客户单位3','2','1','江苏','镇江','润州区','万达广场','666666','666666','18352866666','花','袋装','到付','备注').then((res)=>{
            expect(res.data.extData).toBe("3|测试客户单位3|2|1|江苏|镇江|润州区|万达广场|666666|666666|18352866666|花|袋装|到付|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});